#ifndef defines_h
#define defines_h

#include "typedef.h"
#include <iostream>

// http://www.codeguru.com/forum/showthread.php?t=394932

#ifdef UNICODE
#   define tcout wcout
#   define tcin wcin
#else
#	define tcout cout
#   define tcin cin 
#endif

#ifdef UNICODE
#	define tmemcpy			wmemcpy
#   define tmemmove			wmemmove
#	define tmemset			wmemset
#	define tmemcmp			wmemcmp
#	define tmalloc(c)		((LPTSTR) malloc((c) << 1))
#	define trealloc(p, c)	((LPTSTR) realloc((p), (c) << 1))
#	define talloca(c)		((LPTSTR) _alloca((c) << 1))
#else
#	define tmemcpy			(char*)memcpy
#	define tmemmove			memmove
#	define tmemset			memset
#	define tmemcmp			memcmp
#	define tmalloc(c)		((LPTSTR) malloc(c))
#	define trealloc(p, c)	((LPTSTR) realloc((p), (c)))
#	define talloca(c)		((LPTSTR) _alloca(c))
#endif

// Locale independent ctype (applied to the ASCII characters only)
// isctype/iswctype affects the some non-ASCII characters.
inline int cisctype(TBYTE c, int type)
{
	return (c & (~0x7F)) ? 0 : _isctype(c, type);
}

#define cisalpha(c)		cisctype(c, _ALPHA)
#define cisalnum(c)		cisctype(c, _ALPHA | _DIGIT)
#define cisdigit(c)		cisctype(c, _DIGIT)
#define cisxdigit(c)	cisctype(c, _HEX)
#define cisupper(c)		cisctype(c, _UPPER)
#define cislower(c)		cisctype(c, _LOWER)
#define cisprint(c)		cisctype(c, _ALPHA | _BLANK | _DIGIT | _PUNCT)
#define cisspace(c)		cisctype(c, _SPACE)

inline TCHAR ctoupper(TBYTE c)
{
	return cislower(c) ? (c & ~0x20) : c;
}

inline TCHAR ctolower(TBYTE c)
{
	return cisupper(c) ? (c | 0x20) : c;
}

#endif